package com.example.demo.huawei;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/*
API集群复杂统计
 */
public class OD49_2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 日志的条数
        int n = scanner.nextInt();
        scanner.nextLine();
        // 给定层级 关键字出现的频次
        Map<Integer, Map<String, Integer>> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String s = scanner.nextLine();
            // System.out.println(s);
            String[] strings = s.split("/");

            // j代表层级
            for (int j = 1; j < strings.length; j++) {
                if (map.containsKey(j)) {
                    Map<String, Integer> map1 = map.get(j);
                    if (map1.containsKey(strings[j])) {
                        map1.put(strings[j], map1.get(strings[j]) + 1);
                    } else {
                        map1.put(strings[j], 1);
                    }
                } else {
                    HashMap<String, Integer> hashMap = new HashMap<>();
                    hashMap.put(strings[j], 1);
                    map.put(j, hashMap);
                }
            }
        }


        //层级
        int l = scanner.nextInt();
        String keyword = scanner.next();
        if (map.containsKey(l) && map.get(l).containsKey(keyword)) {
            System.out.println(map.get(l).get(keyword));
        } else {
            System.out.println(0);
        }


    }
}
